package sys_brokerage_base

import "wwt-gin-api/app/model/api_model"

func CreateSysBrokerageBaseCurdFactory() *SysBrokerageBaseCurd {
	return &SysBrokerageBaseCurd{sysBrokerageBaseModel: api_model.CreateSysBrokerageBaseFactory("")}
}

type SysBrokerageBaseCurd struct {
	sysBrokerageBaseModel *api_model.SysBrokerageBase
}

func (receiver *SysBrokerageBaseCurd) GetOne(whereMap map[string]interface{}, column string) *api_model.SysBrokerageBase {
	if len(whereMap) == 0 {
		return nil
	}
	res := api_model.CreateSysBrokerageBaseFactory("")
	for k, val := range whereMap {
		res.DB = res.Where(k+"= ? ", val)
	}
	if column != "" {
		res.DB = res.DB.Select(column)
	}
	res.First(res)
	return res
}

func (receiver *SysBrokerageBaseCurd) GetAll(whereMap map[string]interface{}, column string) []*api_model.SysBrokerageBase {
	if len(whereMap) == 0 {
		return nil
	}
	res := make([]*api_model.SysBrokerageBase, 0)
	model := api_model.CreateSysBrokerageBaseFactory("")
	for k, val := range whereMap {
		model.DB = model.Where(k+"= ? ", val)
	}
	if column != "" {
		model.DB = model.DB.Select(column)
	}
	model.Find(&res)
	return res
}
